/**
 @file knet_kernel.h

 @author  Copyright (C) 2012 Centec Networks Inc.  All rights reserved.

 @date 2012-4-9

 @version v2.0

*/
#ifndef _KNET_KERNEL_H_
#define _KNET_KERNEL_H_
#ifdef __cplusplus
extern "C" {
#endif

#if defined(TSINGMA_MX) || defined(TSINGMA_GX)
#define KNET_MAX_RX_CHAN_NUM     8
#define KNET_MAX_TX_CHAN_NUM     2
#else
#define KNET_MAX_RX_CHAN_NUM     4
#define KNET_MAX_TX_CHAN_NUM     2
#endif

#define KNET_DEV_MAJOR     201

#define KNET_NAME          "linux_knet"  /* "linux_knet" */

#define KNET_DEV_NAME      "/dev/" KNET_NAME

#define KNET_PKT_MTU    9600
#if defined(TSINGMA_MX) || defined(TSINGMA_GX)
/*TMM*/
struct DsDesc_le_s
{
    unsigned int u1_pkt_sop:1;
    unsigned int u1_pkt_eop:1;
    unsigned int u1_pkt_pktError:1;
    unsigned int u1_pkt_truncPkt:1;
    unsigned int u1_pkt_truncEn:1;
    unsigned int u2_pkt_drop:1;
    unsigned int atomic:2;
    unsigned int dataStruct :6;
    unsigned int intrMask : 1;
    unsigned int pause : 1;
    unsigned int done : 1;
    unsigned int error : 1;
    unsigned int descError : 1;
    unsigned int dataError : 1;
    unsigned int cfgSize_20_11_0 : 12;

    unsigned int cfgSize_20_19_12 : 8;
    unsigned int realSize : 20;
    unsigned int valid0 : 1;
    unsigned int descRsv : 3;

    unsigned int TsShift : 4;
    unsigned int memAddr : 28;

    unsigned int tsAddr : 32;

    unsigned int timestamp_64_31_0 : 32;

    unsigned int timestamp_64_63_32 : 32;

    unsigned int tcamScanAddr0 : 32;

    unsigned int u3_config_cfgRsv : 31;
    unsigned int valid : 1;
};
#else
struct DsDesc_le_s
{
    unsigned int u1_pkt_sop:1;
    unsigned int u1_pkt_eop:1;
    unsigned int u1_pkt_pktError:1;
    unsigned int u1_pkt_truncPkt:1;
    unsigned int u1_pkt_truncEn:1;
    unsigned int atomic:2;
    unsigned int rsv0:1;

    unsigned int dataStruct:6;
    unsigned int rsv1:2;

    unsigned int intrMask:1;
    unsigned int pause:1;
    unsigned int rsv2:2;
    unsigned int invalid0:4;

    unsigned int u2_info_timeout:1;
    unsigned int descError:1;
    unsigned int dataError:1;
    unsigned int rsv3:1;
    unsigned int error:1;
    unsigned int rsv4:2;
    unsigned int done:1;

    unsigned int cfgSize:16;
    unsigned int realSize:16;

    unsigned int rsv5:4;
    unsigned int memAddr:28;

    unsigned int chipAddr;
    unsigned int timestamp_l;

    unsigned int timestamp_h:30;
    unsigned int rsv6:2;

    unsigned int desc_padding0;

    unsigned int desc_padding1;
};
typedef struct DsDesc_le_s DsDesc_le_t;
#endif

#if defined(TSINGMA_MX) || defined(TSINGMA_GX)
/*TMM*/
struct DsDesc_be_s
{
    unsigned int cfgSize_20_11_0 : 12;
    unsigned int dataError : 1;
    unsigned int descError : 1;
    unsigned int error : 1;
    unsigned int done : 1;
    unsigned int pause : 1;
    unsigned int intrMask : 1;
    unsigned int dataStruct :6;
    unsigned int atomic:2;
    unsigned int u2_pkt_drop:1;
    unsigned int u1_pkt_truncEn:1;
    unsigned int u1_pkt_truncPkt:1;
    unsigned int u1_pkt_pktError:1;
    unsigned int u1_pkt_eop:1;
    unsigned int u1_pkt_sop:1;

    unsigned int descRsv : 3;
    unsigned int valid0 : 1;
    unsigned int realSize : 20;
    unsigned int cfgSize_20_19_12 : 8;

    unsigned int memAddr : 28;
    unsigned int TsShift : 4;

    unsigned int tsAddr : 32;

    unsigned int timestamp_64_31_0 : 32;

    unsigned int timestamp_64_63_32 : 32;

    unsigned int tcamScanAddr0 : 32;

    unsigned int valid : 1;
    unsigned int u3_config_cfgRsv : 31;
};
#else
struct DsDesc_be_s
{
    unsigned int u2_info_timeout:1;
    unsigned int descError:1;
    unsigned int dataError:1;
    unsigned int rsv3:1;
    unsigned int error:1;
    unsigned int rsv4:2;
    unsigned int done:1;

    unsigned int intrMask:1;
    unsigned int pause:1;
    unsigned int rsv2:2;
    unsigned int invalid0:4;

    unsigned int dataStruct:6;
    unsigned int rsv1:2;

    unsigned int u1_pkt_sop:1;
    unsigned int u1_pkt_eop:1;
    unsigned int u1_pkt_pktError:1;
    unsigned int u1_pkt_truncPkt:1;
    unsigned int u1_pkt_truncEn:1;
    unsigned int atomic:2;
    unsigned int rsv0:1;

    unsigned short realSize;
    unsigned short cfgSize;

    unsigned int memAddr:28;
    unsigned int rsv5:4;

    unsigned int chipAddr;
    unsigned int timestamp_l;

    unsigned int rsv6:2;
    unsigned int timestamp_h:30;

    unsigned int desc_padding0;
    unsigned int desc_padding1;
};
#endif
#ifdef DUET2
typedef struct DsDesc_be_s DsDesc_t;
#else
typedef struct DsDesc_le_s DsDesc_t;
#endif
struct knet_dma_desc_s
{
    DsDesc_t desc_info;
};
typedef struct knet_dma_desc_s knet_dma_desc_t;

    struct ctc_knet_pkt_s
    {
        unsigned int pkt_len;                 /**< pacekt length of data in bytes, include bridge headr */
        unsigned char* data;                  /**< pointer to packet data */
    
        /*retunred parameter*/
        struct sk_buff * skb;                 /*if not NULL need to send packet to net interface, else do nothing*/
        unsigned int if_id;                            /*net interface id that needs to be sent to.*/
    };
    typedef struct ctc_knet_pkt_s ctc_knet_pkt_t;
    typedef
    int (*CTC_KNET_PKT_CB)(unsigned char lchip, ctc_knet_pkt_t* p_pkt, void* user_data);
    
    struct ctc_knet_pkt_rx_cb_register_s
    {
        CTC_KNET_PKT_CB cb;
        void* user_data;
    };
    
    typedef struct ctc_knet_pkt_rx_cb_register_s ctc_knet_pkt_rx_cb_register_t;
    
    extern int ctc_knet_skb_cb_register(unsigned char lchip, ctc_knet_pkt_rx_cb_register_t* p_register);
#ifdef __cplusplus
}
#endif

#endif

